<script setup lang="ts">
import { ref, reactive } from 'vue'
import type { VxePagerEvents } from 'vxe-pc-ui'
import { customTableProps, customTableEmits } from './customTable'
import { useRequestData } from './hooks'

defineOptions({
  name: 'CustomTable',
})

const { lazy, data, loadConfig, pagerConfig } = defineProps(customTableProps)
defineEmits(customTableEmits)

const { loading, tableData, page } = useRequestData(lazy, data, loadConfig, pagerConfig)

const pageChange: VxePagerEvents.PageChange = ({ pageSize, currentPage }) => {
  page.currentPage = currentPage
  page.pageSize = pageSize
}
</script>

<template>
  <div class="custom-table">
    <vxe-table :border="true" :loading="loading" :data="tableData">
      <vxe-column type="seq" width="70"></vxe-column>
      <vxe-column field="name" title="机构" type="expand">
        <template #default="{ row }">
          <vxe-tag :status="row.status" :content="row.tagName"></vxe-tag>
          {{ row.name }}
        </template>
        <template #content="{ row }">
          <vxe-table :data="row.child" height="200">
            <vxe-column field="name" title="姓名"></vxe-column>
            <vxe-column field="sex" title="性别"></vxe-column>
            <vxe-column field="age" title="年龄"></vxe-column>
          </vxe-table>
        </template>
      </vxe-column>
      <vxe-column field="buyPrice" title="买入" sortable></vxe-column>
      <vxe-column field="riseAndFall" title="涨跌bp" sortable></vxe-column>
    </vxe-table>
    <vxe-pager
      v-model:currentPage="page.currentPage"
      v-model:pageSize="page.pageSize"
      :total="page.total"
      @page-change="pageChange"
    >
    </vxe-pager>
  </div>
</template>

<style lang="less"></style>
